<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 11/13/18
 * Time: 5:56 PM
 */
spl_autoload_register(function ($class_name) {
    $file_path = getFilePathOfClassNameWithPSR0(
        $class_name,
        'caroltc\jenkinsapp',
        __DIR__,
        '.php'
    );
    if ($file_path && file_exists($file_path)) {
        /** @noinspection PhpIncludeInspection */
        require_once $file_path;
    }
});#

/**
 * 自动加载规则设置
 * @param $class_name
 * @param $base_namespace
 * @param $base_path
 * @param string $extension
 * @return mixed|null|string
 */
function getFilePathOfClassNameWithPSR0($class_name, $base_namespace, $base_path, $extension = '.php')
{
    if (strpos($class_name, $base_namespace) === 0) {
        $class_file = str_replace($base_namespace, $base_path, $class_name);
        $class_file .= $extension;
        $class_file = str_replace('\\', '/', $class_file);
        return $class_file;
    }
    return null;
}
